package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.vo.NursingTaskByIdVo;
import com.zzyl.nursing.vo.NursingTaskVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 护理任务Mapper接口
 * 
 * @author ruoyi
 * @date 2024-09-27
 */
@Mapper
public interface NursingTaskMapper extends BaseMapper<NursingTask>
{
    /**
     * 查询护理任务
     * 
     * @param id 护理任务主键
     * @return 护理任务
     */
    public NursingTask selectNursingTaskById(Long id);

    /**
     * 查询护理任务列表
     * 
     * @param nursingTaskDto 护理任务
     * @return 护理任务集合
     */
    public List<NursingTaskVo> selectNursingTaskLists(NursingTaskDto nursingTaskDto);

    /**
     * 新增护理任务
     * 
     * @param nursingTask 护理任务
     * @return 结果
     */
    public int insertNursingTask(NursingTask nursingTask);

    /**
     * 修改护理任务
     * 
     * @param nursingTask 护理任务
     * @return 结果
     */
    public int updateNursingTask(NursingTask nursingTask);

    /**
     * 删除护理任务
     * 
     * @param id 护理任务主键
     * @return 结果
     */
    public int deleteNursingTaskById(Long id);

    /**
     * 批量删除护理任务
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteNursingTaskByIds(Long[] ids);




    /**
     * 获取护理人姓名列表
     * @param list
     * @return
     */
    List<String> selectNursingNameList(List<String> list);


    /**
     * 查询护理任务详细信息
     * @param id
     * @return
     */
    @Select("select * from nursing_task nt where id = #{id}")
    NursingTask selectNursingTaskInformationById(Long id);

    @Select("select distinct nl.name from nursing_task nt left join nursing_project_plan np on nt.project_id = np.project_id left join nursing_level nl on np.plan_id = nl.lplan_id where nt.project_id = #{projectId}")
    String selectNursingLeveNameByProjectId(Long projectId);

    @Select("select e.id_card_no from nursing_task nt left join elder e on e.id = nt.elder_id where nt.elder_id = #{elderId}")
    String selectElderIdCard(Long elderId);

    @Update("update nursing_task nt set nt.status = 3,nt.cancel_reason = #{reason} where nt.id = #{taskId}")
    void cancelTask(@Param("reason") String reason,@Param("taskId") Long taskId);

    @Update("update nursing_task nt set nt.status = 2,nt.estimated_server_time = #{estimatedServerTim},nt.mark = #{mark},nt.task_image = #{taskImage} where nt.id = #{taskId}")
    void doTask(@Param("estimatedServerTim") LocalDateTime estimatedServerTim,@Param("mark") String mark,@Param("taskId") Long taskId,@Param("taskImage") String taskImage);

    @Update("update nursing_task nt set nt.estimated_server_time = #{estimatedServerTime} where nt.id = #{taskId}")
    void updateTimeTask(@Param("estimatedServerTime") LocalDateTime estimatedServerTime,@Param("taskId") Long taskId);
}
